package com.team7.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.team7.common.vo.CommonResult;
import com.team7.common.vo.TeacherCheckVo;
import com.team7.dao.CheckTeacherDao;
import com.team7.service.CheckTeacherService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * @program: team7-Object02
 * @description: 讲师审核实现类
 * @author: 王子鑫
 * @create: 2021-10-20 15:47
 **/
@Service
public class CheckTeacherServiceImpl implements CheckTeacherService {

    @Resource
    private CheckTeacherDao checkTeacherDao;

    //查询所有待审核讲师
    @Override
    public CommonResult findCheckTeacher(Integer page, Integer limit, TeacherCheckVo teacherCheckVo) {
        Page<TeacherCheckVo> teacherCheckVoPage = new Page<>();
        QueryWrapper<TeacherCheckVo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(teacherCheckVo.getName())){
            wrapper.like("name",teacherCheckVo.getName());
        }
        if (StringUtils.isNotEmpty(teacherCheckVo.getMobile())){
            wrapper.like("mobile",teacherCheckVo.getMobile());
        }
        if (StringUtils.isNotEmpty(teacherCheckVo.getStatus())){
            wrapper.like("status",teacherCheckVo.getStatus());
        }
        Page<TeacherCheckVo> checkTeacher = checkTeacherDao.findCheckTeacher(teacherCheckVoPage, wrapper);
        return new CommonResult(200,"查询成功",checkTeacher);
    }

    @Override
    public CommonResult changeCheckTeacher(TeacherCheckVo teacherCheckVo) {
        int i = 0;

        if (teacherCheckVo.getCheckStatus().equals("1")){
            checkTeacherDao.updateType(teacherCheckVo.getMobile());
            i = checkTeacherDao.changeCheckTeacher(teacherCheckVo);
            System.out.println(teacherCheckVo);
            System.out.println(i+"222222222222");
        }else {

            i = checkTeacherDao.changeCheckTeacher(teacherCheckVo);
        }
        if (i>0){
            return new CommonResult(200,"修改成功","success");
        }else {
            return new CommonResult(500,"修改失败","default");
        }
    }

    @Override
    public CommonResult changeTeacherInfo(TeacherCheckVo teacherCheckVo) {
        int i = checkTeacherDao.changeTeacherInfo(teacherCheckVo);
        if (i>0){
            return new CommonResult(200,"修改成功","success");
        }else {
            return new CommonResult(500,"修改失败","success");
        }
    }
}
